#include<iostream>
#include<algorithm>

using namespace std;
typedef long long ll;
const int N = 2e5 + 10;
ll a[N];

int main()
{
	int n, k; cin >> n >> k; ll ret = 0;
	for (int i = 1; i <= n; i++)
	{
		cin >> a[i];
	}
	sort(a + 1, a + n+1);

	for (int i = 1; i <= n; i++)
	{
		ll b = a[i] - k;
		ret += (upper_bound(a + 1, a + i, b) - lower_bound(a + 1, a + i, b));
	}
	cout << ret;
	return 0;
}
